package com.yootoo.extpmml.dsl

import groovy.time.Duration
import groovy.time.TimeCategory

class AdapterSpec {
    Closure givenCall
    long rate
    String cron
    Closure scheduleCall
    Closure executeCall

    def every = { Duration time ->
        this.rate = time.toMilliseconds()
    }

    def when = { String expression ->
        this.cron = expression
    }

    def run = { Closure c ->
        this.scheduleCall = c
    }

    def given(Closure closure) {
        closure.resolveStrategy = Closure.DELEGATE_ONLY
        givenCall = closure
    }

    def schedule(Closure closure) {
        closure.resolveStrategy = Closure.DELEGATE_ONLY
        use TimeCategory, {
            closure()
        }
    }


    def execute(Closure closure) {
        closure.resolveStrategy = Closure.DELEGATE_FIRST
        executeCall = closure
    }
}
